358B - Dima and Text Messages - CodeForces Solution


brute force strings *1500

Please click on ads to support us..

Python Code:


tests = int(input())
texts = []
for _ in range(tests + 1):
    texts.append(input())

message = texts.pop()

res = ["<3"]
for z in texts:
    res.append(z)
    res.append("<3")
texte = "".join(res)

possible = True
indice = 0
for c in texte:
    if (z := message.find(c, indice)) > -1:
        indice = z+1
    else:
        possible = False
        break

if possible:
    print("yes")
else:
    print("no")

C++ Code:

#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define pb push_back
#define pi acos(-1)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const unsigned int M = 1000000007;

int main(int argc, char const *argv[]){
    IOS;
    int n;cin>>n;
    bool f=false;
    string s;
    for(int i=1;i<=n;i++){
        string s1;cin>>s1;
        s+="<3"+s1;
    }
    s+="<3";
    int l=s.length();
    string msg;cin>>msg;
    int l1=msg.length();
    int pos=0;
    for(int i=0;i<l1;i++){
        if(msg[i]==s[pos]){
            pos++;
        }
    }
    if(pos==l)cout<<"yes";
    else cout<<"no";
}


Comments

Submit
0 Comments
More Questions

80A - Panoramix's Prediction
1354B - Ternary String
122B - Lucky Substring
266B - Queue at the School
1490A - Dense Array
1650B - DIV + MOD
1549B - Gregor and the Pawn Game
553A - Kyoya and Colored Balls
1364A - XXXXX
1499B - Binary Removals
1569C - Jury Meeting
108A - Palindromic Times
46A - Ball Game
114A - Cifera
776A - A Serial Killer
25B - Phone numbers
1633C - Kill the Monster
1611A - Make Even
1030B - Vasya and Cornfield
1631A - Min Max Swap
1296B - Food Buying
133A - HQ9+
1650D - Twist the Permutation
1209A - Paint the Numbers
1234A - Equalize Prices Again
1613A - Long Comparison
1624B - Make AP
660B - Seating On Bus
405A - Gravity Flip
499B - Lecture